#include "read_thread.h"
#include <QProcess>

read_thread::read_thread(QObject *parent) :
    QThread(parent)
{
    fd = open(DEV3, O_RDWR);
    if(fd < 0)
    {
        printf("error");
        exit(1);
    }

    struct termios Opt;
    tcgetattr(fd,&Opt);      //初始化
    tcflush(fd,TCIFLUSH);
    cfsetispeed(&Opt,BAUT);    //设置波特率
    cfsetospeed(&Opt,BAUT);

    Opt.c_cflag |= CS8;                          //设置数据位
    Opt.c_cflag &= ~PARENB;
    Opt.c_oflag &= ~(OPOST);
    Opt.c_cflag &= ~CSTOPB;
    Opt.c_lflag &= ~(ICANON|ISIG|ECHO|IEXTEN);
    Opt.c_iflag &= ~(INPCK|BRKINT|ICRNL|ISTRIP|IXON);

    Opt.c_cc[VMIN] = 250;            //最大长度
    Opt.c_cc[VTIME] = 1;            //超时时间

    dup2(fd, STDOUT_FILENO);
}

void read_thread::run()
{
    printf("sssssssssssssssss");
    QProcess::execute("/usr/bin/mosquitto_sub -t RGB");
    printf("aaaaaaaaaaaaaaaaaaaa");

}
